package cn.edu.xmu.orderpayment.payment.util.baseobject;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Yujie Lin
 * @date 2021/12/15 13:02
 */
@Data
@AllArgsConstructor
public class Transaction {
    private String tradeSn;

    private String requestSn;

    private LocalDateTime transactionTime;
    private TransactionType transactionType;
    private Long amount;

    public enum TransactionType {
        PAY(0, "支付"),
        REFUND(1, "退款");

        private static final Map<Integer, TransactionType> TYPE_MAP;

        static {
            TYPE_MAP = new HashMap();
            for (TransactionType enum1 : values()) {
                TYPE_MAP.put(enum1.code, enum1);
            }
        }

        private int code;
        private String description;

        TransactionType(int code, String description) {
            this.code = code;
            this.description = description;
        }

        public static TransactionType getTypeByCode(Integer code) {
            return TYPE_MAP.get(code);
        }

        public Integer getCode() {
            return code;
        }

        public String getDescription() {
            return description;
        }

    }
}
